import * as types from "./mutation-types";
import Api from "api/api";
const state = {
  contentList: "",
  saveModel:"",
  TableNameExist:"",
  updateModel:"",
  delModel:"",
  deleteForm:"",
  contentModel:"",
  saveForm:"",
  updateForm:"",
  contentModelForm:"",
  getFrom:""
};

const getters = {
  contentList: state => state.contentList,//模型列表
  saveModel: state => state.saveModel,//保存内容模型
  TableNameExist: state => state.TableNameExist,//判断自定义模型表名是否重复
  updateModel: state => state.updateModel,//更新内容模型接口
  delModel: state => state.delModel,//批量删除自定义模型编号
  deleteForm: state => state.deleteForm,//批量删除内容模型列表
  contentModel: state => state.contentModel,//获取模板内容
  saveForm: state => state.saveForm,//保存内容模型列表接口
  updateForm: state => state.updateForm,//更新内容模型列表接口
  contentModelForm: state => state.contentModelForm,//内容模型列表接口
  getFrom: state => state.getFrom,//获取模板列表内容
};

const actions = {
  //批量删除自定义模型编号
  deleteUsingPOSTS({ commit }, param) {
    return Api.deleteUsingPOST(param).then(ret => {
      commit(types.UPDATE_MODEL_DEL_LIST, ret.data);
      return ret;
    });
  },
  //批量删除内容模型列表
  deleteFormUsingPOSTS({ commit }, param) {
    return Api.deleteFormUsingPOST(param).then(ret => {
      commit(types.UPDATE_DEL_FORM_LIST, ret.data);
      return ret;
    });
  },
  //获取模板内容
  getByIdUsingGETS({ commit }, param) {
    return Api.getByIdUsingGET(param).then(ret => {
      commit(types.UPDATE_BY_ID_LIST, ret.data);
      return ret;
    });
  },
  //模型列表
  listContentModelUsingPOSTS({ commit }, param) {
    return Api.listContentModelUsingPOST(param).then(ret => {
      commit(types.UPDATE_MODEL_LIST_LIST, ret.data);
      return ret;
    });
  },
  //保存内容模型接口
  saveUsingPOSTS({ commit }, param) {
    return Api.saveUsingPOST(param).then(ret => {
      commit(types.UPDATE_SAVE_MODEL_LIST, ret.data);
      return ret;
    });
  },
  //保存内容模型列表接口
  saveFormUsingPOSTS({ commit }, param) {
    return Api.saveFormUsingPOST(param).then(ret => {
      commit(types.UPDATE_SAVE_FORM_LIST, ret.data);
      return ret;
    });
  },
  //判断自定义模型表名是否重复接口
  checkcmTableNameExistUsingGETS({ commit }, param) {
    return Api.checkcmTableNameExistUsingGET(param).then(ret => {
      commit(types.UPDATE_EXIS_MODEL_LIST, ret.data);
      return ret;
    });
  },
  //更新内容模型接口
  updateUsingPOSTS({ commit }, param) {
    return Api.updateUsingPOST(param).then(ret => {
      commit(types.UPDATE_UPDATE_MODEL_LIST, ret.data);
      return ret;
    });
  },
  //更新内容模型列表接口
  updateFormUsingPOSTS({ commit }, param) {
    return Api.updateFormUsingPOST(param).then(ret => {
      commit(types.UPDATE_UPDATE_FORM_LIST, ret.data);
      return ret;
    });
  },
  //内容模型列表接口
  contentModelFormListUsingGETS({ commit }, param) {
    return Api.contentModelFormListUsingGET(param).then(ret => {
      commit(types.UPDATE_CONTENT_MODEL_FORM_LIST, ret.data);
      return ret;
    });
  },
  //获取模板列表内容
  getFromByIdUsingGETS({ commit }, param) {
    return Api.getFromByIdUsingGET(param).then(ret => {
      commit(types.UPDATE_GET_FORM_LIST, ret.data);
      return ret;
    });
  },
};
const mutations = {
  [types.UPDATE_MODEL_LIST_LIST](state, payload) {
    state.contentList = payload;
  },[types.UPDATE_SAVE_MODEL_LIST](state, payload) {
    state.saveModel = payload;
  },[types.UPDATE_EXIS_MODEL_LIST](state, payload) {
    state.TableNameExist = payload;
  },[types.UPDATE_UPDATE_MODEL_LIST](state, payload) {
    state.updateModel = payload;
  },[types.UPDATE_MODEL_DEL_LIST](state, payload) {
    state.delModel = payload;
  },[types.UPDATE_DEL_FORM_LIST](state, payload) {
    state.deleteForm = payload;
  },[types.UPDATE_BY_ID_LIST](state, payload) {
    state.contentModel = payload;
  },[types.UPDATE_SAVE_FORM_LIST](state, payload) {
    state.saveForm = payload;
  },[types.UPDATE_UPDATE_FORM_LIST](state, payload) {
    state.updateForm = payload;
  },[types.UPDATE_CONTENT_MODEL_FORM_LIST](state, payload) {
    state.contentModelForm = payload;
  },[types.UPDATE_GET_FORM_LIST](state, payload) {
    state.getFrom = payload;
  },
};

export default {
  state,
  getters,
  actions,
  mutations
};
